package com.ruoyi.web.controller.system;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.vo.PStoreOrderInfoVo;
import com.ruoyi.system.domain.bo.PStoreOrderInfoBo;
import com.ruoyi.system.service.IPStoreOrderInfoService;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiOperation;

/**
 * 订单购物详情Controller
 *
 * @author ruoyi
 * @date 2022-08-01
 */
@Validated
@Api(value = "订单购物详情控制器", tags = {"订单购物详情管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/storeOrderInfo")
public class PStoreOrderInfoController extends BaseController {

    private final IPStoreOrderInfoService iPStoreOrderInfoService;

    /**
     * 查询订单购物详情列表
     */
    @ApiOperation("查询订单购物详情列表")
    @SaCheckPermission("system:storeOrderInfo:list")
    @GetMapping("/list")
    public TableDataInfo<PStoreOrderInfoVo> list(PStoreOrderInfoBo bo, PageQuery pageQuery) {
        return iPStoreOrderInfoService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出订单购物详情列表
     */
    @ApiOperation("导出订单购物详情列表")
    @SaCheckPermission("system:storeOrderInfo:export")
    @Log(title = "订单购物详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(PStoreOrderInfoBo bo, HttpServletResponse response) {
        List<PStoreOrderInfoVo> list = iPStoreOrderInfoService.queryList(bo);
        ExcelUtil.exportExcel(list, "订单购物详情", PStoreOrderInfoVo.class, response);
    }

    /**
     * 获取订单购物详情详细信息
     */
    @ApiOperation("获取订单购物详情详细信息")
    @SaCheckPermission("system:storeOrderInfo:query")
    @GetMapping("/{id}")
    public R<PStoreOrderInfoVo> getInfo(@ApiParam("主键")
                                     @NotNull(message = "主键不能为空")
                                     @PathVariable("id") Long id) {
        return R.ok(iPStoreOrderInfoService.queryById(id));
    }

    /**
     * 新增订单购物详情
     */
    @ApiOperation("新增订单购物详情")
    @SaCheckPermission("system:storeOrderInfo:add")
    @Log(title = "订单购物详情", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody PStoreOrderInfoBo bo) {
        return toAjax(iPStoreOrderInfoService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改订单购物详情
     */
    @ApiOperation("修改订单购物详情")
    @SaCheckPermission("system:storeOrderInfo:edit")
    @Log(title = "订单购物详情", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody PStoreOrderInfoBo bo) {
        return toAjax(iPStoreOrderInfoService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除订单购物详情
     */
    @ApiOperation("删除订单购物详情")
    @SaCheckPermission("system:storeOrderInfo:remove")
    @Log(title = "订单购物详情", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@ApiParam("主键串")
                                       @NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iPStoreOrderInfoService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
